{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##第一次做的特征，线下F1_score:0.8993"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "#显示所有列\n",
    "pd.set_option('display.max_columns', None)\n",
    "from sklearn.linear_model import LinearRegression\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from sklearn.metrics import f1_score\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from tqdm import tqdm\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "from datetime import datetime\n",
    "import os\n",
    "pd.set_option('display.max_columns',None)\n",
    "pd.set_option('display.max_rows',None)\n",
    "train_list = os.listdir('./hy_round1_train_20200102/')\n",
    "test_list = os.listdir('./hy_round1_testA_20200102/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7000"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(train_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2000"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(test_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2699638, 8)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data = pd.read_csv('train_data.csv')\n",
    "train_data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 特征工程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def create_feature_base(demo):\n",
    "    demo.rename(columns={'渔船ID':'id',\"速度\":'speed','方向':'direction'},inplace=True)\n",
    "    demo_train = pd.DataFrame()  \n",
    "    #构建特征集合\n",
    "    demo = demo[demo['speed']<=20]\n",
    "    #分割time特征得到day,hour,quarter\n",
    "    demo = demo.sort_values(['time'],ascending=True)\n",
    "    demo['time'] = demo['time'].apply(lambda x:datetime.strptime(x,'%m%d %H:%M:%S'))\n",
    "    demo['month'] = demo[\"time\"].dt.month\n",
    "    demo['day'] = demo[\"time\"].dt.day\n",
    "    demo['hour'] = demo[\"time\"].dt.hour\n",
    "    #数据按照时间排序\n",
    "    demo['distance'] = demo['x']**2+demo['y']**2\n",
    "    demo['distance'] = demo['distance'].apply(lambda x:np.sqrt(x))\n",
    "    tmp = demo.groupby(['id','x','y'])['id','x','y'].size().reset_index().rename(columns={0:'count_xy'})\n",
    "    demo = pd.merge(demo,tmp,on=['id','x','y'],how='left')\n",
    "    demo['y_diff1'] = demo['y'].diff(1)\n",
    "    demo['x_diff1'] = demo['x'].diff(1)\n",
    "    demo['y_diff2'] = demo['y'].diff(2)\n",
    "    demo['x_diff2'] = demo['x'].diff(2)\n",
    "    demo['dis_diff1'] = demo['distance'].diff(1)\n",
    "    demo['dis_diff2'] = demo['distance'].diff(2)\n",
    "    demo['speed_diff1'] = demo['speed'].diff(1)\n",
    "    demo['speed_diff2'] = demo['speed'].diff(2) \n",
    "    diff = demo['time'].max()-demo['time'].min()\n",
    "    demo = demo.fillna(0)\n",
    "#     print(demo.iloc[:10])\n",
    "#     print(\"y_diff1的平均值为：\",demo['y_diff1'].mean())\n",
    "#     print(demo['month'].mean())\n",
    "#     start = demo.iloc[0]['time']\n",
    "#     end = demo.iloc[-1]['time']\n",
    "#     diff = datetime.strptime(str(end),\"%m%d %H:%M:%S\") - datetime.strptime(str(start),\"%m%d %H:%M:%S\")\n",
    "    \n",
    "    #构建特征dataframe\n",
    "    demo_train['y_diff1_mean'] = [demo['y_diff1'].mean()]\n",
    "    demo_train['x_diff1_mean'] = demo['x_diff1'].mean()\n",
    "    demo_train['y_diff2_mean'] = demo['y_diff2'].mean()\n",
    "    demo_train['x_diff2_mean'] = demo['x_diff2'].mean()\n",
    "    demo_train['dis_diff1_mean'] = demo['dis_diff1'].mean()\n",
    "    demo_train['dis_diff2_mean'] = demo['dis_diff2'].mean()\n",
    "    demo_train['speed_diff1_mean'] = demo['speed_diff1'].mean()\n",
    "    demo_train['speed_diff2_mean'] = demo['speed_diff2'].mean() \n",
    "    demo_train['y_diff1_std'] = demo['y_diff1'].std()\n",
    "    demo_train['x_diff1_std'] = demo['x_diff1'].std()\n",
    "    demo_train['y_diff2_std'] = demo['y_diff2'].std()\n",
    "    demo_train['x_diff2_std'] = demo['x_diff2'].std()\n",
    "    demo_train['dis_diff1_std'] = demo['dis_diff1'].std()\n",
    "    demo_train['dis_diff2_std'] = demo['dis_diff2'].std()\n",
    "    demo_train['speed_diff1_std'] = demo['speed_diff1'].std()\n",
    "    demo_train['speed_diff2_std'] = demo['speed_diff2'].std()   \n",
    "    demo_train['month'] = demo['month'].mean()\n",
    "    demo_train['day'] = demo['day'].mean()\n",
    "    demo_train['hour'] = demo['hour'].mean()\n",
    "    demo_train['count_xy_std'] = demo['count_xy'].std()\n",
    "    demo_train['count_xy_max'] = demo['count_xy'].max()\n",
    "    demo_train['count_xy_min'] = demo['count_xy'].min()\n",
    "    demo_train['id'] = [demo['id'][0]]\n",
    "    demo_train['work_days'] = diff.days\n",
    "    demo_train['work_hours'] = diff.seconds/3600\n",
    "    \n",
    "    for s in ['x','y','speed','direction','distance']:   #计算x,y,speed,direction,distance的最大、最小、平均、方差\n",
    "        temp = demo.groupby('id')[s].agg({'nunique_'+s:'nunique', 'var_' + s: 'var','min_'+s:'min','max_'+s:'max','mean_'+s:'mean','std_'+s:'std','median_'+s:'median','mod_'+s:lambda x: np.mean(pd.Series.mode(x))})\n",
    "        demo_train = pd.merge(demo_train,temp, on='id',how='left')\n",
    "     #构建x,y坐标交互特征\n",
    "    demo_train['x_max-min'] = demo_train['max_x'] - demo_train['min_x']\n",
    "    demo_train['y_max-min'] = demo_train['max_y'] - demo_train['min_y']\n",
    "    demo_train['area'] = demo_train['y_max-min'] * demo_train['x_max-min']\n",
    "\n",
    "    return demo_train\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████| 7000/7000 [20:53<00:00,  5.89it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(7000, 69)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████████████████████████████████████████████████████████████████████████| 2000/2000 [05:42<00:00,  5.83it/s]\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>y_diff1_mean</th>\n",
       "      <th>x_diff1_mean</th>\n",
       "      <th>y_diff2_mean</th>\n",
       "      <th>x_diff2_mean</th>\n",
       "      <th>dis_diff1_mean</th>\n",
       "      <th>dis_diff2_mean</th>\n",
       "      <th>speed_diff1_mean</th>\n",
       "      <th>speed_diff2_mean</th>\n",
       "      <th>y_diff1_std</th>\n",
       "      <th>x_diff1_std</th>\n",
       "      <th>y_diff2_std</th>\n",
       "      <th>x_diff2_std</th>\n",
       "      <th>dis_diff1_std</th>\n",
       "      <th>dis_diff2_std</th>\n",
       "      <th>speed_diff1_std</th>\n",
       "      <th>speed_diff2_std</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>hour</th>\n",
       "      <th>count_xy_std</th>\n",
       "      <th>count_xy_max</th>\n",
       "      <th>count_xy_min</th>\n",
       "      <th>id</th>\n",
       "      <th>work_days</th>\n",
       "      <th>work_hours</th>\n",
       "      <th>nunique_x</th>\n",
       "      <th>var_x</th>\n",
       "      <th>min_x</th>\n",
       "      <th>max_x</th>\n",
       "      <th>mean_x</th>\n",
       "      <th>std_x</th>\n",
       "      <th>median_x</th>\n",
       "      <th>mod_x</th>\n",
       "      <th>nunique_y</th>\n",
       "      <th>var_y</th>\n",
       "      <th>min_y</th>\n",
       "      <th>max_y</th>\n",
       "      <th>mean_y</th>\n",
       "      <th>std_y</th>\n",
       "      <th>median_y</th>\n",
       "      <th>mod_y</th>\n",
       "      <th>nunique_speed</th>\n",
       "      <th>var_speed</th>\n",
       "      <th>min_speed</th>\n",
       "      <th>max_speed</th>\n",
       "      <th>mean_speed</th>\n",
       "      <th>std_speed</th>\n",
       "      <th>median_speed</th>\n",
       "      <th>mod_speed</th>\n",
       "      <th>nunique_direction</th>\n",
       "      <th>var_direction</th>\n",
       "      <th>min_direction</th>\n",
       "      <th>max_direction</th>\n",
       "      <th>mean_direction</th>\n",
       "      <th>std_direction</th>\n",
       "      <th>median_direction</th>\n",
       "      <th>mod_direction</th>\n",
       "      <th>nunique_distance</th>\n",
       "      <th>var_distance</th>\n",
       "      <th>min_distance</th>\n",
       "      <th>max_distance</th>\n",
       "      <th>mean_distance</th>\n",
       "      <th>std_distance</th>\n",
       "      <th>median_distance</th>\n",
       "      <th>mod_distance</th>\n",
       "      <th>x_max-min</th>\n",
       "      <th>y_max-min</th>\n",
       "      <th>area</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-129.383142</td>\n",
       "      <td>132.452685</td>\n",
       "      <td>-252.350174</td>\n",
       "      <td>262.953353</td>\n",
       "      <td>18.455508</td>\n",
       "      <td>39.557828</td>\n",
       "      <td>-2.112601e-02</td>\n",
       "      <td>-4.168901e-02</td>\n",
       "      <td>1022.652899</td>\n",
       "      <td>816.820992</td>\n",
       "      <td>1895.320120</td>\n",
       "      <td>1528.677414</td>\n",
       "      <td>866.608022</td>\n",
       "      <td>1613.116098</td>\n",
       "      <td>1.761007</td>\n",
       "      <td>2.231864</td>\n",
       "      <td>10.839142</td>\n",
       "      <td>6.498660</td>\n",
       "      <td>11.383378</td>\n",
       "      <td>5.889597</td>\n",
       "      <td>18</td>\n",
       "      <td>1</td>\n",
       "      <td>7000</td>\n",
       "      <td>2</td>\n",
       "      <td>23.625833</td>\n",
       "      <td>160</td>\n",
       "      <td>1.519182e+08</td>\n",
       "      <td>7.069441e+06</td>\n",
       "      <td>7.119130e+06</td>\n",
       "      <td>7.092492e+06</td>\n",
       "      <td>12325.511892</td>\n",
       "      <td>7.087014e+06</td>\n",
       "      <td>7.083957e+06</td>\n",
       "      <td>160</td>\n",
       "      <td>5.942949e+07</td>\n",
       "      <td>5.893360e+06</td>\n",
       "      <td>5.966537e+06</td>\n",
       "      <td>5.918416e+06</td>\n",
       "      <td>7709.052316</td>\n",
       "      <td>5.918174e+06</td>\n",
       "      <td>5.919921e+06</td>\n",
       "      <td>63</td>\n",
       "      <td>8.361991</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.09</td>\n",
       "      <td>1.656139</td>\n",
       "      <td>2.891711</td>\n",
       "      <td>0.22</td>\n",
       "      <td>0.11</td>\n",
       "      <td>147</td>\n",
       "      <td>13380.595636</td>\n",
       "      <td>0</td>\n",
       "      <td>360</td>\n",
       "      <td>137.356568</td>\n",
       "      <td>115.674525</td>\n",
       "      <td>126.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>160</td>\n",
       "      <td>8.752514e+07</td>\n",
       "      <td>9.218302e+06</td>\n",
       "      <td>9.257876e+06</td>\n",
       "      <td>9.237489e+06</td>\n",
       "      <td>9355.487009</td>\n",
       "      <td>9.232341e+06</td>\n",
       "      <td>9.231896e+06</td>\n",
       "      <td>49689.118453</td>\n",
       "      <td>73177.359157</td>\n",
       "      <td>3.636118e+09</td>\n",
       "      <td>测试</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>29.121438</td>\n",
       "      <td>-18.045851</td>\n",
       "      <td>52.485583</td>\n",
       "      <td>-33.934514</td>\n",
       "      <td>4.861156</td>\n",
       "      <td>7.684973</td>\n",
       "      <td>-9.432314e-03</td>\n",
       "      <td>-2.403930e-02</td>\n",
       "      <td>1333.126656</td>\n",
       "      <td>812.582837</td>\n",
       "      <td>2215.551273</td>\n",
       "      <td>1454.061427</td>\n",
       "      <td>1228.109232</td>\n",
       "      <td>2166.576298</td>\n",
       "      <td>2.100528</td>\n",
       "      <td>2.447797</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>11.973799</td>\n",
       "      <td>11.331878</td>\n",
       "      <td>8.982074</td>\n",
       "      <td>35</td>\n",
       "      <td>1</td>\n",
       "      <td>7001</td>\n",
       "      <td>2</td>\n",
       "      <td>23.920833</td>\n",
       "      <td>367</td>\n",
       "      <td>7.470759e+07</td>\n",
       "      <td>6.216428e+06</td>\n",
       "      <td>6.254992e+06</td>\n",
       "      <td>6.239019e+06</td>\n",
       "      <td>8643.355279</td>\n",
       "      <td>6.240004e+06</td>\n",
       "      <td>6.246625e+06</td>\n",
       "      <td>367</td>\n",
       "      <td>3.145945e+08</td>\n",
       "      <td>5.176732e+06</td>\n",
       "      <td>5.242126e+06</td>\n",
       "      <td>5.212498e+06</td>\n",
       "      <td>17736.813086</td>\n",
       "      <td>5.213941e+06</td>\n",
       "      <td>5.241041e+06</td>\n",
       "      <td>76</td>\n",
       "      <td>5.353575</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.09</td>\n",
       "      <td>3.074476</td>\n",
       "      <td>2.313779</td>\n",
       "      <td>3.02</td>\n",
       "      <td>0.11</td>\n",
       "      <td>144</td>\n",
       "      <td>10944.619820</td>\n",
       "      <td>0</td>\n",
       "      <td>356</td>\n",
       "      <td>149.606987</td>\n",
       "      <td>104.616537</td>\n",
       "      <td>185.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>367</td>\n",
       "      <td>3.104271e+08</td>\n",
       "      <td>8.089656e+06</td>\n",
       "      <td>8.157909e+06</td>\n",
       "      <td>8.129918e+06</td>\n",
       "      <td>17618.940093</td>\n",
       "      <td>8.131486e+06</td>\n",
       "      <td>8.154069e+06</td>\n",
       "      <td>38563.864593</td>\n",
       "      <td>65394.204233</td>\n",
       "      <td>2.521853e+09</td>\n",
       "      <td>测试</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>442.490790</td>\n",
       "      <td>427.915494</td>\n",
       "      <td>880.353623</td>\n",
       "      <td>851.758743</td>\n",
       "      <td>611.592427</td>\n",
       "      <td>1217.099651</td>\n",
       "      <td>-2.117073e-02</td>\n",
       "      <td>-3.829268e-02</td>\n",
       "      <td>692.943743</td>\n",
       "      <td>866.037294</td>\n",
       "      <td>1349.652460</td>\n",
       "      <td>1692.571095</td>\n",
       "      <td>1078.336285</td>\n",
       "      <td>2110.051691</td>\n",
       "      <td>1.788539</td>\n",
       "      <td>1.814041</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>18.990244</td>\n",
       "      <td>11.390244</td>\n",
       "      <td>0.252556</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>7002</td>\n",
       "      <td>2</td>\n",
       "      <td>23.765556</td>\n",
       "      <td>396</td>\n",
       "      <td>1.909682e+09</td>\n",
       "      <td>6.566008e+06</td>\n",
       "      <td>6.745702e+06</td>\n",
       "      <td>6.678498e+06</td>\n",
       "      <td>43699.910307</td>\n",
       "      <td>6.670449e+06</td>\n",
       "      <td>6.696588e+06</td>\n",
       "      <td>396</td>\n",
       "      <td>2.611433e+09</td>\n",
       "      <td>5.385267e+06</td>\n",
       "      <td>5.567766e+06</td>\n",
       "      <td>5.482646e+06</td>\n",
       "      <td>51102.185380</td>\n",
       "      <td>5.457670e+06</td>\n",
       "      <td>5.506761e+06</td>\n",
       "      <td>89</td>\n",
       "      <td>6.590845</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.09</td>\n",
       "      <td>2.985488</td>\n",
       "      <td>2.567264</td>\n",
       "      <td>2.00</td>\n",
       "      <td>0.70</td>\n",
       "      <td>163</td>\n",
       "      <td>12897.346824</td>\n",
       "      <td>0</td>\n",
       "      <td>359</td>\n",
       "      <td>159.436585</td>\n",
       "      <td>113.566486</td>\n",
       "      <td>153.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>396</td>\n",
       "      <td>4.331304e+09</td>\n",
       "      <td>8.491970e+06</td>\n",
       "      <td>8.745881e+06</td>\n",
       "      <td>8.640714e+06</td>\n",
       "      <td>65812.642583</td>\n",
       "      <td>8.619462e+06</td>\n",
       "      <td>8.670003e+06</td>\n",
       "      <td>179694.146963</td>\n",
       "      <td>182498.814846</td>\n",
       "      <td>3.279397e+10</td>\n",
       "      <td>测试</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.262346</td>\n",
       "      <td>-0.233907</td>\n",
       "      <td>0.514321</td>\n",
       "      <td>0.008219</td>\n",
       "      <td>-0.009053</td>\n",
       "      <td>0.338548</td>\n",
       "      <td>1.371452e-18</td>\n",
       "      <td>-1.959217e-19</td>\n",
       "      <td>541.611693</td>\n",
       "      <td>770.528668</td>\n",
       "      <td>1044.932738</td>\n",
       "      <td>1513.718826</td>\n",
       "      <td>422.150981</td>\n",
       "      <td>819.728001</td>\n",
       "      <td>1.260876</td>\n",
       "      <td>1.704997</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>15.503529</td>\n",
       "      <td>11.482353</td>\n",
       "      <td>111.825309</td>\n",
       "      <td>242</td>\n",
       "      <td>1</td>\n",
       "      <td>7003</td>\n",
       "      <td>2</td>\n",
       "      <td>23.911389</td>\n",
       "      <td>71</td>\n",
       "      <td>2.495917e+08</td>\n",
       "      <td>6.150675e+06</td>\n",
       "      <td>6.205663e+06</td>\n",
       "      <td>6.160467e+06</td>\n",
       "      <td>15798.471167</td>\n",
       "      <td>6.150875e+06</td>\n",
       "      <td>6.150875e+06</td>\n",
       "      <td>71</td>\n",
       "      <td>5.192916e+07</td>\n",
       "      <td>5.174729e+06</td>\n",
       "      <td>5.206247e+06</td>\n",
       "      <td>5.202435e+06</td>\n",
       "      <td>7206.189166</td>\n",
       "      <td>5.206031e+06</td>\n",
       "      <td>5.206031e+06</td>\n",
       "      <td>49</td>\n",
       "      <td>7.210279</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.09</td>\n",
       "      <td>1.132212</td>\n",
       "      <td>2.685196</td>\n",
       "      <td>0.22</td>\n",
       "      <td>0.11</td>\n",
       "      <td>147</td>\n",
       "      <td>14310.037825</td>\n",
       "      <td>0</td>\n",
       "      <td>360</td>\n",
       "      <td>122.242353</td>\n",
       "      <td>119.624570</td>\n",
       "      <td>100.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>71</td>\n",
       "      <td>6.285184e+07</td>\n",
       "      <td>8.058142e+06</td>\n",
       "      <td>8.080988e+06</td>\n",
       "      <td>8.063307e+06</td>\n",
       "      <td>7927.915297</td>\n",
       "      <td>8.058289e+06</td>\n",
       "      <td>8.058289e+06</td>\n",
       "      <td>54988.582897</td>\n",
       "      <td>31518.136446</td>\n",
       "      <td>1.733138e+09</td>\n",
       "      <td>测试</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-50.927131</td>\n",
       "      <td>44.349179</td>\n",
       "      <td>-98.268184</td>\n",
       "      <td>88.944626</td>\n",
       "      <td>1.300192</td>\n",
       "      <td>5.093128</td>\n",
       "      <td>-9.095477e-03</td>\n",
       "      <td>-7.060302e-03</td>\n",
       "      <td>731.529380</td>\n",
       "      <td>766.757692</td>\n",
       "      <td>1382.760199</td>\n",
       "      <td>1434.558325</td>\n",
       "      <td>478.010409</td>\n",
       "      <td>868.090103</td>\n",
       "      <td>1.651751</td>\n",
       "      <td>1.898973</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>8.472362</td>\n",
       "      <td>11.811558</td>\n",
       "      <td>112.989783</td>\n",
       "      <td>239</td>\n",
       "      <td>1</td>\n",
       "      <td>7004</td>\n",
       "      <td>2</td>\n",
       "      <td>23.580278</td>\n",
       "      <td>100</td>\n",
       "      <td>2.984384e+08</td>\n",
       "      <td>6.348864e+06</td>\n",
       "      <td>6.407177e+06</td>\n",
       "      <td>6.357542e+06</td>\n",
       "      <td>17275.368489</td>\n",
       "      <td>6.349065e+06</td>\n",
       "      <td>6.349065e+06</td>\n",
       "      <td>100</td>\n",
       "      <td>2.675751e+08</td>\n",
       "      <td>5.343990e+06</td>\n",
       "      <td>5.406460e+06</td>\n",
       "      <td>5.398000e+06</td>\n",
       "      <td>16357.722009</td>\n",
       "      <td>5.406460e+06</td>\n",
       "      <td>5.406460e+06</td>\n",
       "      <td>59</td>\n",
       "      <td>7.379748</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.09</td>\n",
       "      <td>1.473442</td>\n",
       "      <td>2.716569</td>\n",
       "      <td>0.22</td>\n",
       "      <td>0.11</td>\n",
       "      <td>158</td>\n",
       "      <td>13602.971558</td>\n",
       "      <td>0</td>\n",
       "      <td>355</td>\n",
       "      <td>123.839196</td>\n",
       "      <td>116.631778</td>\n",
       "      <td>116.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100</td>\n",
       "      <td>2.104244e+07</td>\n",
       "      <td>8.333525e+06</td>\n",
       "      <td>8.362510e+06</td>\n",
       "      <td>8.340101e+06</td>\n",
       "      <td>4587.204303</td>\n",
       "      <td>8.339091e+06</td>\n",
       "      <td>8.339091e+06</td>\n",
       "      <td>58313.120520</td>\n",
       "      <td>62469.471390</td>\n",
       "      <td>3.642790e+09</td>\n",
       "      <td>测试</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   y_diff1_mean  x_diff1_mean  y_diff2_mean  x_diff2_mean  dis_diff1_mean  \\\n",
       "0   -129.383142    132.452685   -252.350174    262.953353       18.455508   \n",
       "0     29.121438    -18.045851     52.485583    -33.934514        4.861156   \n",
       "0    442.490790    427.915494    880.353623    851.758743      611.592427   \n",
       "0      0.262346     -0.233907      0.514321      0.008219       -0.009053   \n",
       "0    -50.927131     44.349179    -98.268184     88.944626        1.300192   \n",
       "\n",
       "   dis_diff2_mean  speed_diff1_mean  speed_diff2_mean  y_diff1_std  \\\n",
       "0       39.557828     -2.112601e-02     -4.168901e-02  1022.652899   \n",
       "0        7.684973     -9.432314e-03     -2.403930e-02  1333.126656   \n",
       "0     1217.099651     -2.117073e-02     -3.829268e-02   692.943743   \n",
       "0        0.338548      1.371452e-18     -1.959217e-19   541.611693   \n",
       "0        5.093128     -9.095477e-03     -7.060302e-03   731.529380   \n",
       "\n",
       "   x_diff1_std  y_diff2_std  x_diff2_std  dis_diff1_std  dis_diff2_std  \\\n",
       "0   816.820992  1895.320120  1528.677414     866.608022    1613.116098   \n",
       "0   812.582837  2215.551273  1454.061427    1228.109232    2166.576298   \n",
       "0   866.037294  1349.652460  1692.571095    1078.336285    2110.051691   \n",
       "0   770.528668  1044.932738  1513.718826     422.150981     819.728001   \n",
       "0   766.757692  1382.760199  1434.558325     478.010409     868.090103   \n",
       "\n",
       "   speed_diff1_std  speed_diff2_std      month        day       hour  \\\n",
       "0         1.761007         2.231864  10.839142   6.498660  11.383378   \n",
       "0         2.100528         2.447797  11.000000  11.973799  11.331878   \n",
       "0         1.788539         1.814041  11.000000  18.990244  11.390244   \n",
       "0         1.260876         1.704997  11.000000  15.503529  11.482353   \n",
       "0         1.651751         1.898973  11.000000   8.472362  11.811558   \n",
       "\n",
       "   count_xy_std  count_xy_max  count_xy_min    id  work_days  work_hours  \\\n",
       "0      5.889597            18             1  7000          2   23.625833   \n",
       "0      8.982074            35             1  7001          2   23.920833   \n",
       "0      0.252556             2             1  7002          2   23.765556   \n",
       "0    111.825309           242             1  7003          2   23.911389   \n",
       "0    112.989783           239             1  7004          2   23.580278   \n",
       "\n",
       "   nunique_x         var_x         min_x         max_x        mean_x  \\\n",
       "0        160  1.519182e+08  7.069441e+06  7.119130e+06  7.092492e+06   \n",
       "0        367  7.470759e+07  6.216428e+06  6.254992e+06  6.239019e+06   \n",
       "0        396  1.909682e+09  6.566008e+06  6.745702e+06  6.678498e+06   \n",
       "0         71  2.495917e+08  6.150675e+06  6.205663e+06  6.160467e+06   \n",
       "0        100  2.984384e+08  6.348864e+06  6.407177e+06  6.357542e+06   \n",
       "\n",
       "          std_x      median_x         mod_x  nunique_y         var_y  \\\n",
       "0  12325.511892  7.087014e+06  7.083957e+06        160  5.942949e+07   \n",
       "0   8643.355279  6.240004e+06  6.246625e+06        367  3.145945e+08   \n",
       "0  43699.910307  6.670449e+06  6.696588e+06        396  2.611433e+09   \n",
       "0  15798.471167  6.150875e+06  6.150875e+06         71  5.192916e+07   \n",
       "0  17275.368489  6.349065e+06  6.349065e+06        100  2.675751e+08   \n",
       "\n",
       "          min_y         max_y        mean_y         std_y      median_y  \\\n",
       "0  5.893360e+06  5.966537e+06  5.918416e+06   7709.052316  5.918174e+06   \n",
       "0  5.176732e+06  5.242126e+06  5.212498e+06  17736.813086  5.213941e+06   \n",
       "0  5.385267e+06  5.567766e+06  5.482646e+06  51102.185380  5.457670e+06   \n",
       "0  5.174729e+06  5.206247e+06  5.202435e+06   7206.189166  5.206031e+06   \n",
       "0  5.343990e+06  5.406460e+06  5.398000e+06  16357.722009  5.406460e+06   \n",
       "\n",
       "          mod_y  nunique_speed  var_speed  min_speed  max_speed  mean_speed  \\\n",
       "0  5.919921e+06             63   8.361991        0.0      10.09    1.656139   \n",
       "0  5.241041e+06             76   5.353575        0.0      10.09    3.074476   \n",
       "0  5.506761e+06             89   6.590845        0.0      10.09    2.985488   \n",
       "0  5.206031e+06             49   7.210279        0.0      10.09    1.132212   \n",
       "0  5.406460e+06             59   7.379748        0.0      10.09    1.473442   \n",
       "\n",
       "   std_speed  median_speed  mod_speed  nunique_direction  var_direction  \\\n",
       "0   2.891711          0.22       0.11                147   13380.595636   \n",
       "0   2.313779          3.02       0.11                144   10944.619820   \n",
       "0   2.567264          2.00       0.70                163   12897.346824   \n",
       "0   2.685196          0.22       0.11                147   14310.037825   \n",
       "0   2.716569          0.22       0.11                158   13602.971558   \n",
       "\n",
       "   min_direction  max_direction  mean_direction  std_direction  \\\n",
       "0              0            360      137.356568     115.674525   \n",
       "0              0            356      149.606987     104.616537   \n",
       "0              0            359      159.436585     113.566486   \n",
       "0              0            360      122.242353     119.624570   \n",
       "0              0            355      123.839196     116.631778   \n",
       "\n",
       "   median_direction  mod_direction  nunique_distance  var_distance  \\\n",
       "0             126.0            0.0               160  8.752514e+07   \n",
       "0             185.0           40.0               367  3.104271e+08   \n",
       "0             153.0           50.0               396  4.331304e+09   \n",
       "0             100.0            0.0                71  6.285184e+07   \n",
       "0             116.0            0.0               100  2.104244e+07   \n",
       "\n",
       "   min_distance  max_distance  mean_distance  std_distance  median_distance  \\\n",
       "0  9.218302e+06  9.257876e+06   9.237489e+06   9355.487009     9.232341e+06   \n",
       "0  8.089656e+06  8.157909e+06   8.129918e+06  17618.940093     8.131486e+06   \n",
       "0  8.491970e+06  8.745881e+06   8.640714e+06  65812.642583     8.619462e+06   \n",
       "0  8.058142e+06  8.080988e+06   8.063307e+06   7927.915297     8.058289e+06   \n",
       "0  8.333525e+06  8.362510e+06   8.340101e+06   4587.204303     8.339091e+06   \n",
       "\n",
       "   mod_distance      x_max-min      y_max-min          area type  \n",
       "0  9.231896e+06   49689.118453   73177.359157  3.636118e+09   测试  \n",
       "0  8.154069e+06   38563.864593   65394.204233  2.521853e+09   测试  \n",
       "0  8.670003e+06  179694.146963  182498.814846  3.279397e+10   测试  \n",
       "0  8.058289e+06   54988.582897   31518.136446  1.733138e+09   测试  \n",
       "0  8.339091e+06   58313.120520   62469.471390  3.642790e+09   测试  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train = pd.DataFrame()\n",
    "for file in tqdm(train_list):\n",
    "    demo = pd.read_csv('./hy_round1_train_20200102/'+file)\n",
    "    demo_train = create_feature_base(demo)\n",
    "    demo_train['type'] = demo['type']\n",
    "    train = train.append(demo_train)\n",
    "print(train.shape)\n",
    "test = pd.DataFrame()\n",
    "for file in tqdm(test_list):\n",
    "    demo = pd.read_csv('./hy_round1_testA_20200102/'+file)\n",
    "    demo_test = create_feature_base(demo)\n",
    "    demo_test['type'] = '测试'\n",
    "    test = test.append(demo_test)\n",
    "test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "拖网    4361\n",
       "测试    2000\n",
       "围网    1621\n",
       "刺网    1018\n",
       "Name: type, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = train.append(test).reset_index(drop=True)\n",
    "#data.to_csv('./input/data.csv',index=False)\n",
    "data['type'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['type'] = data['type'].map({'测试':-1,'刺网':0,'围网':1,'拖网':2})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       " 2    4361\n",
       "-1    2000\n",
       " 1    1621\n",
       " 0    1018\n",
       "Name: type, dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['type'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mem. usage decreased to  1.73 Mb (63.6% reduction)\n"
     ]
    }
   ],
   "source": [
    "#降低内存使用\n",
    "def reduce_mem_usage(df, verbose=True):\n",
    "    numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']\n",
    "    start_mem = df.memory_usage().sum() / 1024**2    \n",
    "    for col in df.columns:\n",
    "        col_type = df[col].dtypes\n",
    "        if col_type in numerics:\n",
    "            c_min = df[col].min()\n",
    "            c_max = df[col].max()\n",
    "            if str(col_type)[:3] == 'int':\n",
    "                if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:\n",
    "                    df[col] = df[col].astype(np.int8)\n",
    "                elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:\n",
    "                    df[col] = df[col].astype(np.int16)\n",
    "                elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:\n",
    "                    df[col] = df[col].astype(np.int32)\n",
    "                elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:\n",
    "                    df[col] = df[col].astype(np.int64)  \n",
    "            else:\n",
    "                if c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:\n",
    "                    df[col] = df[col].astype(np.float16)\n",
    "                elif c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:\n",
    "                    df[col] = df[col].astype(np.float32)\n",
    "                else:\n",
    "                    df[col] = df[col].astype(np.float64)    \n",
    "    end_mem = df.memory_usage().sum() / 1024**2\n",
    "    if verbose: print('Mem. usage decreased to {:5.2f} Mb ({:.1f}% reduction)'.format(end_mem, 100 * (start_mem - end_mem) / start_mem))\n",
    "    return df\n",
    "\n",
    "data = reduce_mem_usage(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import KFold\n",
    "from sklearn.metrics import confusion_matrix\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "import lightgbm as lgb\n",
    "#分离训练集和测试集\n",
    "train = data[data['type']!=-1]\n",
    "test = data[data['type']==-1]\n",
    "features = [i for i in train.columns if i not in ['id','time','type']]\n",
    "train_y = train['type']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2000 \n",
      " 拖网    1235\n",
      "围网     490\n",
      "刺网     275\n",
      "Name: predict, dtype: int64\n",
      "        id predict\n",
      "7000  7000      围网\n",
      "7001  7001      拖网\n",
      "7002  7002      围网\n",
      "7003  7003      拖网\n",
      "7004  7004      围网\n",
      "10折情况下： 0.8908843736296695\n"
     ]
    }
   ],
   "source": [
    "train_x = train[features]\n",
    "test_x = test[features]\n",
    "cv_pred = []\n",
    "oof = train[['id']]\n",
    "cms = np.zeros((len(set(train_y)),len(set(train_y))))   #混淆矩阵\n",
    "skf = StratifiedKFold(n_splits=10, random_state=28, shuffle=True)\n",
    "\n",
    "feature_importances = pd.DataFrame()\n",
    "feature_importances['feature'] = train_x.columns\n",
    "\n",
    "for index, (train_index, val_index) in enumerate(skf.split(train_x, train_y)):\n",
    "    \n",
    "#     lgb_model = lgb.LGBMClassifier(\n",
    "#         boosting_type=\"gbdt\", num_leaves=120, reg_alpha=0, reg_lambda=0.,\n",
    "#         max_depth=-1, n_estimators=800, objective='multiclass', class_weight='balanced',\n",
    "#         subsample=0.9, colsample_bytree=0.5, subsample_freq=1,min_child_samples=7,\n",
    "#         learning_rate=0.03, random_state=2018 + index, n_jobs=10, metric=\"None\", importance_type='gain'\n",
    "#     )\n",
    "    \n",
    "    lgb_model = lgb.LGBMClassifier(\n",
    "        boosting_type=\"gbdt\", num_leaves=120, reg_alpha=0, reg_lambda=1.,\n",
    "        max_depth=10, n_estimators=2600, objective='multiclass', class_weight='balanced',\n",
    "        subsample=0.8, colsample_bytree=0.5, subsample_freq=1,min_child_samples=7,\n",
    "        learning_rate=0.03, random_state=2018 + index, n_jobs=-1, metric=\"None\", importance_type='gain'\n",
    "    )\n",
    "    \n",
    "    train_x1, val_x1, train_y1, val_y1 = \\\n",
    "    train_x.loc[train_index], train_x.loc[val_index], train_y.loc[train_index], train_y.loc[val_index]\n",
    "\n",
    "    lgb_model.fit(train_x1, train_y1)\n",
    "    \n",
    "    #out of folder预测\n",
    "    oof.loc[val_index] = lgb_model.predict(val_x1).reshape(-1, 1)\n",
    "    \n",
    "    #测试集预测\n",
    "    test_y = lgb_model.predict(test_x)\n",
    "\n",
    "    # Confusion matrix by folds\n",
    "    cms += confusion_matrix(train_y.loc[val_index], oof.loc[val_index])\n",
    " \n",
    "    #特征重要性\n",
    "    feature_importances['fold_{}'.format(index + 1)] = lgb_model.feature_importances_\n",
    "    \n",
    "    if index == 0:\n",
    "        cv_pred = np.array(test_y).reshape(-1, 1)\n",
    "    else:\n",
    "        cv_pred = np.hstack((cv_pred, np.array(test_y).reshape(-1, 1)))\n",
    "#投票策略筛选预测结果\n",
    "submit = []\n",
    "for line in cv_pred:\n",
    "    submit.append(np.argmax(np.bincount(line)))\n",
    "#预测结果\n",
    "res = test[['id']]\n",
    "res['predict'] = submit\n",
    "res['predict'] = res['predict'].map({0:'刺网',1:'围网',2:'拖网'})\n",
    "\n",
    "print(len(res), '\\n',res.predict.value_counts())\n",
    "print(res.sort_values('id').head())\n",
    "\n",
    "#保存模型\n",
    "res.sort_values('id').to_csv('submission0110_2.csv', index=False, header=False)\n",
    "print(\"10折情况下：\",f1_score(y_true=train[['type']], y_pred=oof, average='macro'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.891489708828351"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#oof F1-score\n",
    "from sklearn.metrics import f1_score\n",
    "f1_score(y_true=train[['type']], y_pred=oof, average='macro')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>feature</th>\n",
       "      <th>fold_1</th>\n",
       "      <th>fold_2</th>\n",
       "      <th>fold_3</th>\n",
       "      <th>fold_4</th>\n",
       "      <th>fold_5</th>\n",
       "      <th>importance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>mean_y</td>\n",
       "      <td>17664.686808</td>\n",
       "      <td>14087.627929</td>\n",
       "      <td>12655.662884</td>\n",
       "      <td>10165.705453</td>\n",
       "      <td>10150.142883</td>\n",
       "      <td>64723.825957</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>area</td>\n",
       "      <td>15421.841578</td>\n",
       "      <td>12971.478044</td>\n",
       "      <td>9446.152661</td>\n",
       "      <td>12568.835488</td>\n",
       "      <td>13122.998080</td>\n",
       "      <td>63531.305852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>mod_y</td>\n",
       "      <td>10451.537668</td>\n",
       "      <td>7681.494932</td>\n",
       "      <td>10545.464009</td>\n",
       "      <td>13089.688066</td>\n",
       "      <td>17705.004660</td>\n",
       "      <td>59473.189336</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>min_y</td>\n",
       "      <td>9017.870788</td>\n",
       "      <td>11166.584095</td>\n",
       "      <td>14720.805268</td>\n",
       "      <td>11517.444234</td>\n",
       "      <td>10904.584252</td>\n",
       "      <td>57327.288637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>median_y</td>\n",
       "      <td>9810.051490</td>\n",
       "      <td>9650.559672</td>\n",
       "      <td>7552.951267</td>\n",
       "      <td>9595.912666</td>\n",
       "      <td>8741.072651</td>\n",
       "      <td>45350.547746</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>max_y</td>\n",
       "      <td>6223.320145</td>\n",
       "      <td>8095.696348</td>\n",
       "      <td>8783.607197</td>\n",
       "      <td>9791.206841</td>\n",
       "      <td>7925.486887</td>\n",
       "      <td>40819.317418</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>mod_distance</td>\n",
       "      <td>6301.024742</td>\n",
       "      <td>8808.469628</td>\n",
       "      <td>7917.825387</td>\n",
       "      <td>6380.775136</td>\n",
       "      <td>5786.063380</td>\n",
       "      <td>35194.158273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>median_speed</td>\n",
       "      <td>5181.822460</td>\n",
       "      <td>5421.111522</td>\n",
       "      <td>6124.042766</td>\n",
       "      <td>6098.741611</td>\n",
       "      <td>5970.404310</td>\n",
       "      <td>28796.122668</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>min_distance</td>\n",
       "      <td>6118.960075</td>\n",
       "      <td>6417.345228</td>\n",
       "      <td>4368.272330</td>\n",
       "      <td>5819.013578</td>\n",
       "      <td>5763.550636</td>\n",
       "      <td>28487.141846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>var_distance</td>\n",
       "      <td>3584.714588</td>\n",
       "      <td>4980.787170</td>\n",
       "      <td>7612.348609</td>\n",
       "      <td>6182.156675</td>\n",
       "      <td>5773.814760</td>\n",
       "      <td>28133.821803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>mod_x</td>\n",
       "      <td>4314.073431</td>\n",
       "      <td>4590.099609</td>\n",
       "      <td>4712.869560</td>\n",
       "      <td>4922.549391</td>\n",
       "      <td>4802.167551</td>\n",
       "      <td>23341.759542</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>x_max-min</td>\n",
       "      <td>4660.442964</td>\n",
       "      <td>4911.724239</td>\n",
       "      <td>5944.530329</td>\n",
       "      <td>4845.276061</td>\n",
       "      <td>2891.625394</td>\n",
       "      <td>23253.598987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>min_x</td>\n",
       "      <td>3825.456103</td>\n",
       "      <td>4010.662912</td>\n",
       "      <td>4236.804312</td>\n",
       "      <td>4002.723481</td>\n",
       "      <td>4490.953281</td>\n",
       "      <td>20566.600090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>max_x</td>\n",
       "      <td>3653.815280</td>\n",
       "      <td>3197.330302</td>\n",
       "      <td>3493.382199</td>\n",
       "      <td>3352.353502</td>\n",
       "      <td>4671.359483</td>\n",
       "      <td>18368.240765</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>median_x</td>\n",
       "      <td>3436.962907</td>\n",
       "      <td>4110.823491</td>\n",
       "      <td>3590.108688</td>\n",
       "      <td>3778.275240</td>\n",
       "      <td>3224.188297</td>\n",
       "      <td>18140.358623</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>max_distance</td>\n",
       "      <td>3332.781431</td>\n",
       "      <td>4316.365101</td>\n",
       "      <td>3188.679102</td>\n",
       "      <td>4232.387433</td>\n",
       "      <td>2829.353392</td>\n",
       "      <td>17899.566458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>y_max-min</td>\n",
       "      <td>4695.649373</td>\n",
       "      <td>3659.353696</td>\n",
       "      <td>2080.402362</td>\n",
       "      <td>3255.649239</td>\n",
       "      <td>4118.463890</td>\n",
       "      <td>17809.518560</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>nunique_direction</td>\n",
       "      <td>3421.376842</td>\n",
       "      <td>3205.083515</td>\n",
       "      <td>2799.978399</td>\n",
       "      <td>3267.406931</td>\n",
       "      <td>3243.211963</td>\n",
       "      <td>15937.057651</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>var_speed</td>\n",
       "      <td>3272.789102</td>\n",
       "      <td>3033.287671</td>\n",
       "      <td>3199.301139</td>\n",
       "      <td>2862.504822</td>\n",
       "      <td>3563.149756</td>\n",
       "      <td>15931.032490</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>mean_x</td>\n",
       "      <td>2872.709179</td>\n",
       "      <td>2493.179950</td>\n",
       "      <td>3676.117372</td>\n",
       "      <td>3085.117582</td>\n",
       "      <td>2762.089945</td>\n",
       "      <td>14889.214028</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>count_xy_max</td>\n",
       "      <td>2575.803596</td>\n",
       "      <td>2905.746557</td>\n",
       "      <td>2652.616378</td>\n",
       "      <td>2760.073150</td>\n",
       "      <td>2684.668308</td>\n",
       "      <td>13578.907988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>count_xy_std</td>\n",
       "      <td>2794.037553</td>\n",
       "      <td>2506.163358</td>\n",
       "      <td>2518.695739</td>\n",
       "      <td>3058.045934</td>\n",
       "      <td>2629.715569</td>\n",
       "      <td>13506.658154</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>mean_direction</td>\n",
       "      <td>3028.070158</td>\n",
       "      <td>2436.658245</td>\n",
       "      <td>2769.348777</td>\n",
       "      <td>2373.507585</td>\n",
       "      <td>2892.860935</td>\n",
       "      <td>13500.445700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>var_y</td>\n",
       "      <td>1726.167849</td>\n",
       "      <td>2466.158981</td>\n",
       "      <td>2527.041729</td>\n",
       "      <td>2366.514384</td>\n",
       "      <td>3200.023793</td>\n",
       "      <td>12285.906736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>std_speed</td>\n",
       "      <td>2174.144935</td>\n",
       "      <td>2881.317119</td>\n",
       "      <td>1933.148339</td>\n",
       "      <td>2464.053427</td>\n",
       "      <td>2547.424228</td>\n",
       "      <td>12000.088048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>mean_speed</td>\n",
       "      <td>2491.916021</td>\n",
       "      <td>2290.245435</td>\n",
       "      <td>2283.205447</td>\n",
       "      <td>2420.702247</td>\n",
       "      <td>2450.668811</td>\n",
       "      <td>11936.737960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>speed_diff2_mean</td>\n",
       "      <td>2759.739075</td>\n",
       "      <td>2558.800436</td>\n",
       "      <td>2188.279097</td>\n",
       "      <td>2057.069910</td>\n",
       "      <td>2288.294365</td>\n",
       "      <td>11852.182883</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>speed_diff1_mean</td>\n",
       "      <td>2496.823429</td>\n",
       "      <td>2639.345787</td>\n",
       "      <td>2519.867797</td>\n",
       "      <td>1641.803925</td>\n",
       "      <td>2058.817702</td>\n",
       "      <td>11356.658639</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>median_distance</td>\n",
       "      <td>2015.241780</td>\n",
       "      <td>1858.009848</td>\n",
       "      <td>2813.655699</td>\n",
       "      <td>2711.658194</td>\n",
       "      <td>1948.447364</td>\n",
       "      <td>11347.012884</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>speed_diff2_std</td>\n",
       "      <td>2519.850484</td>\n",
       "      <td>2168.939396</td>\n",
       "      <td>2505.711692</td>\n",
       "      <td>1999.326137</td>\n",
       "      <td>2052.731884</td>\n",
       "      <td>11246.559593</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>std_distance</td>\n",
       "      <td>1897.796325</td>\n",
       "      <td>2655.487515</td>\n",
       "      <td>2771.285709</td>\n",
       "      <td>1982.820840</td>\n",
       "      <td>1176.843733</td>\n",
       "      <td>10484.234123</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>nunique_x</td>\n",
       "      <td>2120.505409</td>\n",
       "      <td>1980.670539</td>\n",
       "      <td>2561.242927</td>\n",
       "      <td>1679.056135</td>\n",
       "      <td>2072.256223</td>\n",
       "      <td>10413.731233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>max_speed</td>\n",
       "      <td>1883.074075</td>\n",
       "      <td>2117.293968</td>\n",
       "      <td>2055.592110</td>\n",
       "      <td>1906.482450</td>\n",
       "      <td>2219.114663</td>\n",
       "      <td>10181.557266</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>mean_distance</td>\n",
       "      <td>2247.776486</td>\n",
       "      <td>1491.226194</td>\n",
       "      <td>1898.682044</td>\n",
       "      <td>2228.420476</td>\n",
       "      <td>2094.842505</td>\n",
       "      <td>9960.947704</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>x_diff2_std</td>\n",
       "      <td>1972.400274</td>\n",
       "      <td>2065.253400</td>\n",
       "      <td>1678.255915</td>\n",
       "      <td>1805.019751</td>\n",
       "      <td>1743.162318</td>\n",
       "      <td>9264.091658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>speed_diff1_std</td>\n",
       "      <td>1823.399257</td>\n",
       "      <td>1684.449999</td>\n",
       "      <td>1958.643543</td>\n",
       "      <td>1766.257694</td>\n",
       "      <td>1842.505355</td>\n",
       "      <td>9075.255848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>y_diff2_std</td>\n",
       "      <td>2143.252266</td>\n",
       "      <td>1415.150742</td>\n",
       "      <td>1487.267662</td>\n",
       "      <td>1974.325458</td>\n",
       "      <td>1964.732044</td>\n",
       "      <td>8984.728172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>var_direction</td>\n",
       "      <td>1485.220771</td>\n",
       "      <td>1614.902209</td>\n",
       "      <td>1643.503229</td>\n",
       "      <td>1894.542070</td>\n",
       "      <td>1920.013251</td>\n",
       "      <td>8558.181530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>y_diff1_std</td>\n",
       "      <td>1781.382308</td>\n",
       "      <td>1484.049210</td>\n",
       "      <td>1402.897778</td>\n",
       "      <td>1735.886291</td>\n",
       "      <td>1634.041709</td>\n",
       "      <td>8038.257295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>day</td>\n",
       "      <td>1585.516658</td>\n",
       "      <td>1646.874138</td>\n",
       "      <td>1534.301475</td>\n",
       "      <td>1663.567206</td>\n",
       "      <td>1586.239420</td>\n",
       "      <td>8016.498897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>mod_speed</td>\n",
       "      <td>1819.483123</td>\n",
       "      <td>1823.033611</td>\n",
       "      <td>1405.466188</td>\n",
       "      <td>1367.456826</td>\n",
       "      <td>1436.911931</td>\n",
       "      <td>7852.351678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>var_x</td>\n",
       "      <td>1649.105932</td>\n",
       "      <td>1579.770459</td>\n",
       "      <td>1577.518010</td>\n",
       "      <td>1532.818358</td>\n",
       "      <td>1505.859107</td>\n",
       "      <td>7845.071866</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>nunique_speed</td>\n",
       "      <td>1229.526002</td>\n",
       "      <td>1714.213730</td>\n",
       "      <td>1385.755870</td>\n",
       "      <td>1793.552773</td>\n",
       "      <td>1210.052768</td>\n",
       "      <td>7333.101144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>median_direction</td>\n",
       "      <td>1512.123639</td>\n",
       "      <td>1536.660767</td>\n",
       "      <td>1503.353766</td>\n",
       "      <td>1384.303471</td>\n",
       "      <td>1345.282501</td>\n",
       "      <td>7281.724145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>hour</td>\n",
       "      <td>1397.211063</td>\n",
       "      <td>1426.053088</td>\n",
       "      <td>1349.658160</td>\n",
       "      <td>1328.037983</td>\n",
       "      <td>1458.636404</td>\n",
       "      <td>6959.596697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>x_diff1_std</td>\n",
       "      <td>1274.223967</td>\n",
       "      <td>1179.499859</td>\n",
       "      <td>1560.140149</td>\n",
       "      <td>1797.932095</td>\n",
       "      <td>1118.286916</td>\n",
       "      <td>6930.082986</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>std_y</td>\n",
       "      <td>1130.349442</td>\n",
       "      <td>1394.761803</td>\n",
       "      <td>1118.220795</td>\n",
       "      <td>795.804576</td>\n",
       "      <td>1164.752665</td>\n",
       "      <td>5603.889282</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>dis_diff2_std</td>\n",
       "      <td>1199.185667</td>\n",
       "      <td>1121.368863</td>\n",
       "      <td>1003.875247</td>\n",
       "      <td>969.562940</td>\n",
       "      <td>939.396363</td>\n",
       "      <td>5233.389080</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>work_hours</td>\n",
       "      <td>921.956605</td>\n",
       "      <td>1177.770346</td>\n",
       "      <td>1005.472423</td>\n",
       "      <td>1027.928593</td>\n",
       "      <td>1003.160920</td>\n",
       "      <td>5136.288887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>std_direction</td>\n",
       "      <td>1014.412079</td>\n",
       "      <td>905.317053</td>\n",
       "      <td>1051.410607</td>\n",
       "      <td>994.882327</td>\n",
       "      <td>1031.897589</td>\n",
       "      <td>4997.919656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>dis_diff1_std</td>\n",
       "      <td>1091.164236</td>\n",
       "      <td>919.413435</td>\n",
       "      <td>1042.535941</td>\n",
       "      <td>908.042978</td>\n",
       "      <td>962.955815</td>\n",
       "      <td>4924.112406</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>nunique_y</td>\n",
       "      <td>847.393745</td>\n",
       "      <td>1009.842677</td>\n",
       "      <td>982.130717</td>\n",
       "      <td>752.586236</td>\n",
       "      <td>1201.462196</td>\n",
       "      <td>4793.415571</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>y_diff1_mean</td>\n",
       "      <td>1033.173501</td>\n",
       "      <td>1037.796321</td>\n",
       "      <td>953.120864</td>\n",
       "      <td>893.822541</td>\n",
       "      <td>855.180115</td>\n",
       "      <td>4773.093342</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>dis_diff1_mean</td>\n",
       "      <td>719.378381</td>\n",
       "      <td>956.170134</td>\n",
       "      <td>949.060261</td>\n",
       "      <td>1006.908906</td>\n",
       "      <td>783.871539</td>\n",
       "      <td>4415.389221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>max_direction</td>\n",
       "      <td>757.063936</td>\n",
       "      <td>855.845614</td>\n",
       "      <td>1034.510645</td>\n",
       "      <td>820.762610</td>\n",
       "      <td>891.123911</td>\n",
       "      <td>4359.306717</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>std_x</td>\n",
       "      <td>720.114311</td>\n",
       "      <td>795.375200</td>\n",
       "      <td>756.869574</td>\n",
       "      <td>652.512365</td>\n",
       "      <td>913.839265</td>\n",
       "      <td>3838.710715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>x_diff1_mean</td>\n",
       "      <td>779.116933</td>\n",
       "      <td>752.934173</td>\n",
       "      <td>711.056362</td>\n",
       "      <td>789.970299</td>\n",
       "      <td>799.619904</td>\n",
       "      <td>3832.697672</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>y_diff2_mean</td>\n",
       "      <td>749.054431</td>\n",
       "      <td>744.476924</td>\n",
       "      <td>760.978288</td>\n",
       "      <td>786.845407</td>\n",
       "      <td>789.866007</td>\n",
       "      <td>3831.221057</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>dis_diff2_mean</td>\n",
       "      <td>746.562287</td>\n",
       "      <td>694.602969</td>\n",
       "      <td>772.661094</td>\n",
       "      <td>806.906291</td>\n",
       "      <td>657.155307</td>\n",
       "      <td>3677.887948</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>nunique_distance</td>\n",
       "      <td>664.565219</td>\n",
       "      <td>780.873781</td>\n",
       "      <td>630.874884</td>\n",
       "      <td>352.284404</td>\n",
       "      <td>579.145361</td>\n",
       "      <td>3007.743648</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>x_diff2_mean</td>\n",
       "      <td>547.233697</td>\n",
       "      <td>615.980536</td>\n",
       "      <td>623.281130</td>\n",
       "      <td>620.116115</td>\n",
       "      <td>588.523399</td>\n",
       "      <td>2995.134878</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>min_speed</td>\n",
       "      <td>179.451198</td>\n",
       "      <td>188.332140</td>\n",
       "      <td>250.368433</td>\n",
       "      <td>171.061973</td>\n",
       "      <td>214.871193</td>\n",
       "      <td>1004.084937</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>month</td>\n",
       "      <td>174.291548</td>\n",
       "      <td>202.493764</td>\n",
       "      <td>156.990940</td>\n",
       "      <td>176.804438</td>\n",
       "      <td>206.746068</td>\n",
       "      <td>917.326757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>count_xy_min</td>\n",
       "      <td>193.519483</td>\n",
       "      <td>95.057318</td>\n",
       "      <td>186.103287</td>\n",
       "      <td>222.339070</td>\n",
       "      <td>157.895024</td>\n",
       "      <td>854.914182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>mod_direction</td>\n",
       "      <td>227.758800</td>\n",
       "      <td>148.887447</td>\n",
       "      <td>181.887336</td>\n",
       "      <td>85.847468</td>\n",
       "      <td>176.231210</td>\n",
       "      <td>820.612261</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>work_days</td>\n",
       "      <td>21.766143</td>\n",
       "      <td>7.176109</td>\n",
       "      <td>4.143391</td>\n",
       "      <td>2.671554</td>\n",
       "      <td>14.421824</td>\n",
       "      <td>50.179021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>min_direction</td>\n",
       "      <td>20.723810</td>\n",
       "      <td>3.778328</td>\n",
       "      <td>2.045110</td>\n",
       "      <td>1.746734</td>\n",
       "      <td>0.891011</td>\n",
       "      <td>29.184993</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              feature        fold_1        fold_2        fold_3        fold_4  \\\n",
       "36             mean_y  17664.686808  14087.627929  12655.662884  10165.705453   \n",
       "66               area  15421.841578  12971.478044   9446.152661  12568.835488   \n",
       "39              mod_y  10451.537668   7681.494932  10545.464009  13089.688066   \n",
       "34              min_y   9017.870788  11166.584095  14720.805268  11517.444234   \n",
       "38           median_y   9810.051490   9650.559672   7552.951267   9595.912666   \n",
       "35              max_y   6223.320145   8095.696348   8783.607197   9791.206841   \n",
       "63       mod_distance   6301.024742   8808.469628   7917.825387   6380.775136   \n",
       "46       median_speed   5181.822460   5421.111522   6124.042766   6098.741611   \n",
       "58       min_distance   6118.960075   6417.345228   4368.272330   5819.013578   \n",
       "57       var_distance   3584.714588   4980.787170   7612.348609   6182.156675   \n",
       "31              mod_x   4314.073431   4590.099609   4712.869560   4922.549391   \n",
       "64          x_max-min   4660.442964   4911.724239   5944.530329   4845.276061   \n",
       "26              min_x   3825.456103   4010.662912   4236.804312   4002.723481   \n",
       "27              max_x   3653.815280   3197.330302   3493.382199   3352.353502   \n",
       "30           median_x   3436.962907   4110.823491   3590.108688   3778.275240   \n",
       "59       max_distance   3332.781431   4316.365101   3188.679102   4232.387433   \n",
       "65          y_max-min   4695.649373   3659.353696   2080.402362   3255.649239   \n",
       "48  nunique_direction   3421.376842   3205.083515   2799.978399   3267.406931   \n",
       "41          var_speed   3272.789102   3033.287671   3199.301139   2862.504822   \n",
       "28             mean_x   2872.709179   2493.179950   3676.117372   3085.117582   \n",
       "20       count_xy_max   2575.803596   2905.746557   2652.616378   2760.073150   \n",
       "19       count_xy_std   2794.037553   2506.163358   2518.695739   3058.045934   \n",
       "52     mean_direction   3028.070158   2436.658245   2769.348777   2373.507585   \n",
       "33              var_y   1726.167849   2466.158981   2527.041729   2366.514384   \n",
       "45          std_speed   2174.144935   2881.317119   1933.148339   2464.053427   \n",
       "44         mean_speed   2491.916021   2290.245435   2283.205447   2420.702247   \n",
       "7    speed_diff2_mean   2759.739075   2558.800436   2188.279097   2057.069910   \n",
       "6    speed_diff1_mean   2496.823429   2639.345787   2519.867797   1641.803925   \n",
       "62    median_distance   2015.241780   1858.009848   2813.655699   2711.658194   \n",
       "15    speed_diff2_std   2519.850484   2168.939396   2505.711692   1999.326137   \n",
       "61       std_distance   1897.796325   2655.487515   2771.285709   1982.820840   \n",
       "24          nunique_x   2120.505409   1980.670539   2561.242927   1679.056135   \n",
       "43          max_speed   1883.074075   2117.293968   2055.592110   1906.482450   \n",
       "60      mean_distance   2247.776486   1491.226194   1898.682044   2228.420476   \n",
       "11        x_diff2_std   1972.400274   2065.253400   1678.255915   1805.019751   \n",
       "14    speed_diff1_std   1823.399257   1684.449999   1958.643543   1766.257694   \n",
       "10        y_diff2_std   2143.252266   1415.150742   1487.267662   1974.325458   \n",
       "49      var_direction   1485.220771   1614.902209   1643.503229   1894.542070   \n",
       "8         y_diff1_std   1781.382308   1484.049210   1402.897778   1735.886291   \n",
       "17                day   1585.516658   1646.874138   1534.301475   1663.567206   \n",
       "47          mod_speed   1819.483123   1823.033611   1405.466188   1367.456826   \n",
       "25              var_x   1649.105932   1579.770459   1577.518010   1532.818358   \n",
       "40      nunique_speed   1229.526002   1714.213730   1385.755870   1793.552773   \n",
       "54   median_direction   1512.123639   1536.660767   1503.353766   1384.303471   \n",
       "18               hour   1397.211063   1426.053088   1349.658160   1328.037983   \n",
       "9         x_diff1_std   1274.223967   1179.499859   1560.140149   1797.932095   \n",
       "37              std_y   1130.349442   1394.761803   1118.220795    795.804576   \n",
       "13      dis_diff2_std   1199.185667   1121.368863   1003.875247    969.562940   \n",
       "23         work_hours    921.956605   1177.770346   1005.472423   1027.928593   \n",
       "53      std_direction   1014.412079    905.317053   1051.410607    994.882327   \n",
       "12      dis_diff1_std   1091.164236    919.413435   1042.535941    908.042978   \n",
       "32          nunique_y    847.393745   1009.842677    982.130717    752.586236   \n",
       "0        y_diff1_mean   1033.173501   1037.796321    953.120864    893.822541   \n",
       "4      dis_diff1_mean    719.378381    956.170134    949.060261   1006.908906   \n",
       "51      max_direction    757.063936    855.845614   1034.510645    820.762610   \n",
       "29              std_x    720.114311    795.375200    756.869574    652.512365   \n",
       "1        x_diff1_mean    779.116933    752.934173    711.056362    789.970299   \n",
       "2        y_diff2_mean    749.054431    744.476924    760.978288    786.845407   \n",
       "5      dis_diff2_mean    746.562287    694.602969    772.661094    806.906291   \n",
       "56   nunique_distance    664.565219    780.873781    630.874884    352.284404   \n",
       "3        x_diff2_mean    547.233697    615.980536    623.281130    620.116115   \n",
       "42          min_speed    179.451198    188.332140    250.368433    171.061973   \n",
       "16              month    174.291548    202.493764    156.990940    176.804438   \n",
       "21       count_xy_min    193.519483     95.057318    186.103287    222.339070   \n",
       "55      mod_direction    227.758800    148.887447    181.887336     85.847468   \n",
       "22          work_days     21.766143      7.176109      4.143391      2.671554   \n",
       "50      min_direction     20.723810      3.778328      2.045110      1.746734   \n",
       "\n",
       "          fold_5    importance  \n",
       "36  10150.142883  64723.825957  \n",
       "66  13122.998080  63531.305852  \n",
       "39  17705.004660  59473.189336  \n",
       "34  10904.584252  57327.288637  \n",
       "38   8741.072651  45350.547746  \n",
       "35   7925.486887  40819.317418  \n",
       "63   5786.063380  35194.158273  \n",
       "46   5970.404310  28796.122668  \n",
       "58   5763.550636  28487.141846  \n",
       "57   5773.814760  28133.821803  \n",
       "31   4802.167551  23341.759542  \n",
       "64   2891.625394  23253.598987  \n",
       "26   4490.953281  20566.600090  \n",
       "27   4671.359483  18368.240765  \n",
       "30   3224.188297  18140.358623  \n",
       "59   2829.353392  17899.566458  \n",
       "65   4118.463890  17809.518560  \n",
       "48   3243.211963  15937.057651  \n",
       "41   3563.149756  15931.032490  \n",
       "28   2762.089945  14889.214028  \n",
       "20   2684.668308  13578.907988  \n",
       "19   2629.715569  13506.658154  \n",
       "52   2892.860935  13500.445700  \n",
       "33   3200.023793  12285.906736  \n",
       "45   2547.424228  12000.088048  \n",
       "44   2450.668811  11936.737960  \n",
       "7    2288.294365  11852.182883  \n",
       "6    2058.817702  11356.658639  \n",
       "62   1948.447364  11347.012884  \n",
       "15   2052.731884  11246.559593  \n",
       "61   1176.843733  10484.234123  \n",
       "24   2072.256223  10413.731233  \n",
       "43   2219.114663  10181.557266  \n",
       "60   2094.842505   9960.947704  \n",
       "11   1743.162318   9264.091658  \n",
       "14   1842.505355   9075.255848  \n",
       "10   1964.732044   8984.728172  \n",
       "49   1920.013251   8558.181530  \n",
       "8    1634.041709   8038.257295  \n",
       "17   1586.239420   8016.498897  \n",
       "47   1436.911931   7852.351678  \n",
       "25   1505.859107   7845.071866  \n",
       "40   1210.052768   7333.101144  \n",
       "54   1345.282501   7281.724145  \n",
       "18   1458.636404   6959.596697  \n",
       "9    1118.286916   6930.082986  \n",
       "37   1164.752665   5603.889282  \n",
       "13    939.396363   5233.389080  \n",
       "23   1003.160920   5136.288887  \n",
       "53   1031.897589   4997.919656  \n",
       "12    962.955815   4924.112406  \n",
       "32   1201.462196   4793.415571  \n",
       "0     855.180115   4773.093342  \n",
       "4     783.871539   4415.389221  \n",
       "51    891.123911   4359.306717  \n",
       "29    913.839265   3838.710715  \n",
       "1     799.619904   3832.697672  \n",
       "2     789.866007   3831.221057  \n",
       "5     657.155307   3677.887948  \n",
       "56    579.145361   3007.743648  \n",
       "3     588.523399   2995.134878  \n",
       "42    214.871193   1004.084937  \n",
       "16    206.746068    917.326757  \n",
       "21    157.895024    854.914182  \n",
       "55    176.231210    820.612261  \n",
       "22     14.421824     50.179021  \n",
       "50      0.891011     29.184993  "
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_importances['importance'] = feature_importances[[i for i in feature_importances.columns if i != 'feature']].apply(lambda x: x.sum(), axis=1)\n",
    "feature_importances.sort_values(by='importance',ascending=False, inplace=True)\n",
    "feature_importances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2000 \n",
      " 拖网    1244\n",
      "围网     486\n",
      "刺网     270\n",
      "Name: predict, dtype: int64\n",
      "        id predict\n",
      "7000  7000      围网\n",
      "7001  7001      拖网\n",
      "7002  7002      围网\n",
      "7003  7003      拖网\n",
      "7004  7004      围网\n"
     ]
    }
   ],
   "source": [
    "#投票策略筛选预测结果\n",
    "submit = []\n",
    "for line in cv_pred:\n",
    "    submit.append(np.argmax(np.bincount(line)))\n",
    "#预测结果\n",
    "res = test[['id']]\n",
    "res['predict'] = submit\n",
    "res['predict'] = res['predict'].map({0:'刺网',1:'围网',2:'拖网'})\n",
    "\n",
    "print(len(res), '\\n',res.predict.value_counts())\n",
    "print(res.sort_values('id').head())\n",
    "\n",
    "#保存模型\n",
    "res.sort_values('id').to_csv('submission0110.csv', index=False, header=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
